package com.itheima.web.controller;

import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 操作User的controller对象
 *
 *
 */
@RestController
@Slf4j
public class UserController2 {

    /*spring会自动注入对象*/
    @Autowired
    private UserMapper userMapper;

    @GetMapping("/selectById2")
    public User selectById(Integer id) {
        //直接使用mapper即可
        User user = userMapper.selectById(id);
        log.info("读取到id为{}的数据：{}",id,user);
        System.out.println(user);
        return user;
    }
}
